const app = getApp();
Page({
  data: {
    screenIndex: 0,
    priceSort: 0,
    list: [],
    page: 0,
    randomList: [],
  },
  onLoad: function(options) {
    let that = this;
    that.setData({
      search: options.value,
      options: options,
      error_img: wx.getStorageSync('error_img'),
    })
    that.getInfo();
  },
  getInfo(e){
    let that = this;
    let page = that.data.page + 1;
    let city_id = wx.getStorageSync('city_id');
    let category_id = that.options.id || '';
    let search = that.data.search || '';
    app.request('service/serviceList',{
      page, city_id, category_id, search
    },'GET',false,function(res){
      var list = that.data.list
      list.push(...res.data.data.data)
      if(list.length == 0){
        that.getRandomList()
      }
      that.setData({
        pageShow: true,
        list: list,
        page: page,
        pageEmpty: list.length == 0?true:false
      })
    })
  },  
  getRandomList(){
    var that = this;
    let city_id = wx.getStorageSync('city_id');
    app.request('service/serviceRandomList',{city_id},'GET',false,function(res){
      var randomList = that.data.list;
      randomList.push(...res.data.data.data)
      that.setData({
        randomList
      })
    })
  },
  getFormid(e) {
    app.getFormid(e);
  },
  skipPage: function(e) {
    app.skipPage(e);
  },
  searchInput(e){
    this.setData({
      search: e.detail.value,
    })
  },
  search(e) {
    let that = this;
    that.setData({
      page: 0,
      list: [],
    },()=>{
      that.getInfo();
    })
  },
  onReachBottom: function() {
    var that = this;
    if(!that.data.pageEmpty){
      that.getInfo();
    }
  },
  onShareAppMessage: function() {

  }
})